var configModuleDashboardOuvert = 0;
function dialogAjouterModule() {
  var d = $("#dialogAddModule");
  d.dialog("destroy");
  var btns = {};
  btns[BUTTON_CLOSE] = function() {$(this).dialog("destroy")};
  d.dialog({resizable:false, autoOpen:false, height:"auto", width:"auto", buttons:btns});
  d.dialog("open");
  d = $("#button4");
  var a = $("#retour");
  new AjaxUpload(d, {action:baseUrl + "/Dashboard/ajoutermodule/", name:"userfile", data:{folder:"/public/tmp/module"}, onSubmit:function(b, c) {
    if(!(c && /^(zip)$/i.test(c))) {
      a.html('<span style="color:red">' + DASHBOARD_FILE + '</a>');
      return false
    }
    a.html("Envoi du fichier");
    this.disable()
  }, onComplete:function(b, c) {
    if(c == "1") {
      a.html(a.html() + "<br/>");
      $("#tabs").tabs("load", tabOuverte["dashboard/configuration/"].index)
    }else {
      a.html(a.html() + "<br/>" + MISC_ERROR + c)
    }
  }})
}
function deleteModule(d) {
  $.ajax({type:"POST", url:baseUrl + "/Dashboard/desinstallerModule/nom/" + d, success:function(a) {
    if(a == 1) {
      alertGrowl(DASHBOARD_CONFIG_TXT, DASHBOARD_MODULE_SUCCESS);
      $(this).dialog("close");
      navigationToolbar("dashboard_configuration_panel", "dashboard/configuration/")
    }else {
      alertGrowl(DASHBOARD_CONFIG_TXT, DASHBOARD_MODULE_ERROR)
    }
  }})
}
valid.add("deleteModule", deleteModule);
$(function() {
  function d(a, b) {
    var c = a.item.context.firstElementChild.defaultValue;
    b == "add" ? $.ajax({type:"POST", url:baseUrl + "/Dashboard/ajoutermoduleutilisateur/user/" + idU + "/module/" + c, success:function(e) {
      if(e == 1) {
        $("#tabs").tabs("load", 0);
        alertGrowl(DASHBOARD_CONFIG_TXT, DASHBOARD_MODULE_SUCCESS2);
        navigationToolbar("dashboard_configuration_panel", "dashboard/configuration/")
      }else {
        alertGrowl(DASHBOARD_CONFIG_TXT, DASHBOARD_MODULE_ERROR2)
      }
    }}) : $.ajax({type:"POST", url:baseUrl + "/Dashboard/retirermoduleutilisateur/user/" + idU + "/module/" + c, success:function(e) {
      if(e == 1) {
        $("#tabs").tabs("load", 0);
        alertGrowl(DASHBOARD_CONFIG_TXT, DASHBOARD_MODULE_SUCCESS3);
        navigationToolbar("dashboard_configuration_panel", "dashboard/configuration/")
      }else {
        alertGrowl(DASHBOARD_CONFIG_TXT, DASHBOARD_MODULE_ERROR)
      }
    }})
  }
  $("#dashboard_list1").sortable({connectWith:".dashboardList", receive:function(a, b) {
    d(b, "remove")
  }});
  $("#dashboard_list2").sortable({connectWith:".dashboardList", receive:function(a, b) {
    d(b, "add")
  }});
  $("#dashboard_list1, #dashboard_list2").disableSelection();
  $("#config_enregistrer_module").click(function() {
    var a = $("#config_libelle_module").val(), b = $("#config_url_module").val(), c = $("#config_desc_module").val(), e = $("[name=config_refresh_module]:checked").length;
    if(a.trim() == "" || b.trim() == "" || e != 1) {
      alertGrowl(DASHBOARD_CONFIG_TXT, DASHBOARD_MODULE_ERROR3)
    }else {
      e = $("[name=config_refresh_module]:checked").attr("value");
      a = $.URLEncode(a);
      b = $.URLEncode(b);
      c = $.URLEncode(c);
      $.ajax({type:"POST", url:baseUrl + "/Dashboard/ajoutermodule/libelle/" + a + "/url/" + b + "/desc/" + c + "/refresh/" + e, success:function(f) {
        alertGrowl(DASHBOARD_CONFIG_TXT, f);
        navigationToolbar("dashboard_configuration_panel", "dashboard/selectionnerform/")
      }})
    }
  });
  $("#descriptionDashboard").tooltip({delay:0, track:true, fade:250})
});